home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / ansi / hercules.zip / GRAPH.ASM < prev    next >
Assembly Source File  |  1986-09-04  |  3KB  |  133 lines

  1. ;*******************************************************
  2. ;*    
  3. ;*    SET OF GRAPHICS ROUTINES FOR HERCULES BIOS
  4. ;*
  5. ;*        Dave Tutelman - 8/86
  6. ;*
  7. ;*-------------------------------------------------------
  8. ;*
  9. ;*    do_pixel:    draws, erases, or reads a pixel, given an
  10. ;*            offset and mask.
  11. ;*
  12. ;**********************************************************
  13. ;
  14. INCLUDE    hercbios.h
  15.  
  16. ;------------------------------------------
  17. public    wr_pixel,end_herc
  18. extrn    exit_herc_bios:near
  19. ;-----------------------------------------
  20. ;
  21. cseg    segment    public
  22.     assume    cs:cseg,ds:bios_data
  23. ;
  24. ;
  25. ;**********************************************
  26. ;*
  27. ;*    read or write a pixel:
  28. ;*        DX = row # ( y )
  29. ;*        CX = col # ( x )
  30. ;*        AH = 12 for write, 13 for read
  31. ;*        AL = value (0,1, if bit 7=1 EXOR the value)
  32. ;*
  33. ;**********************************************
  34. ;
  35. wr_pixel:
  36.     mov    bh,video_mode    ; check for valid mode
  37.     cmp    bh,herc_mode
  38.     je    do_pixel
  39.     cmp    bh,ibm_mode
  40.     je    do_pixel
  41.     jmp    exit_herc_bios        ; invalid mode. don't do it.
  42. ;
  43. do_pixel:
  44.     push    ax        ; save function and pixel value
  45. ;
  46. ;            ; first compute the address of byte to be modified
  47. ;            ; = 90*[row/4] + [col/8] + 2^D*[row/4] + 2^F*page
  48.     mov    bh,cl        ; col (low order) in BH
  49.     mov    bl,dl        ; row (low order) in BL
  50.     and    bx,0703H    ; mask the col & row remainders
  51. IFDEF iAPX286
  52.     shr    cx,3        ; col / 8
  53.     shr    dx,2        ; row / 4
  54.     mov    al,90
  55.     mul    dx        ; AX = 90*[ row/4 ]
  56.     add    ax,cx        ;  ... + col/8
  57.     shl    bl,5        ; align row remainder
  58. ELSE            ; same as above, obscure but fast for 8086
  59.     shr    cx,1        ; divide col by 8
  60.     shr    cx,1
  61.     shr    cx,1
  62.     shr    dx,1        ; divide row by 4
  63.     shr    dx,1
  64.     shl    dx,1        ; begin fast multiply by 90 (1011010 B)
  65.     mov    ax,dx
  66.     shl    dx,1
  67.     shl    dx,1
  68.     add    ax,dx
  69.     shl    dx,1
  70.     add    ax,dx
  71.     shl    dx,1
  72.     shl    dx,1
  73.     add    ax,dx        ; end fast multiply by 90
  74.     add    ax,cx        ; add on the col/8
  75.     shl    bl,1        ; align row remainder
  76.     shl    bl,1
  77.     shl    bl,1
  78.     shl    bl,1
  79.     shl    bl,1
  80. ENDIF
  81.     add    ah,bl        ; use aligned row remainder
  82.     cmp    active_page,0    ; page 0 active?
  83.     je    end_adr_calc    ; yup
  84.     or    ah,80H        ; page 1 active. Set MSB of address
  85. end_adr_calc:        ; address of byte is now in AX
  86. ;
  87.     mov    dx,pixbase    ; base of pixel display to DX
  88.     mov    es,dx        ; ...and thence to segment reg
  89.     mov    si,ax        ; address of byte w/ pixel to index reg
  90.     mov    cl,bh        ; bit addr in byte
  91.     mov    al,80H        ; '1000 0000' in AL 
  92.     shr    al,cl        ; shift mask to line up with bit to read/write
  93.     mov    bl,al    
  94. ;
  95.     pop    bx        ; now retrieve original AX into BX
  96.                 ;      function=BH, pixel value=BL
  97.     cmp    bh,13        ; what to do with the pixel?
  98.     je    read_pix    ; read the pixel.
  99.     cmp    bl,0        ; write the pixel. But how?
  100.     je    clr_pix        ; clear the pixel
  101.     jl    exor_pix    ; exclusive-or the pixel
  102. ;
  103. set_pix:        ; set the pixel
  104.     or    es:[si],al    ; or the mask with the right byte
  105.     jmp    exit_herc_bios
  106. ;
  107. clr_pix:        ;clear the pixel
  108.     not    al        ; invert the mask, so zero on bit to be cleared
  109.     and    es:[si],al    ; and the mask with the right byte
  110.     jmp    exit_herc_bios
  111. ;
  112. exor_pix:        ; exclusive-or the pixel
  113.     mov    ah,07fH        ; mask to rid 7th bit
  114.     and    ah,bl        ; pixval w/o XOR flag
  115.     jnz    do_exor        ; ExOr with a 1?
  116.     jmp    exit_herc_bios    ; no! XOR (0,x) = x. just return.
  117. do_exor:
  118.     xor    es:[si],al    ; EXOR the pixel with the mask.
  119.     jmp    exit_herc_bios
  120. ;
  121. read_pix:        ; read the pixel
  122.     and    al,es:[si]    ; read the bit into AL
  123.     jz    rd_zro
  124.     mov    al,1        ; if it ain't zero, it's one
  125. rd_zro:    jmp    exit_herc_bios
  126. ;
  127. ;
  128. end_herc:            ; label for end of package. Used by hercbios
  129.                 ;    to install it.
  130. ;
  131. cseg    ends
  132.     end
  133.